<?php
namespace app\index\controller;

use think\Controller;
use think\Db;
class FileSalary extends Common{

    //基础信息类页面渲染
    public function index(){
        return $this->fetch();
    }
    //编辑页面
    public function edit(){
        $id = request()->param('id');
        $info = Db('user')
        ->alias("user")
        ->join('filesalary_info', 'user.id = filesalary_info.user_id')
        ->where('user.id','=',$id)
        ->find();
        $this->assign('info', $info);
        return $this->fetch();
    }
    //基础信息表格数据渲染
    public function getfilesalary(){
        $page = request()->param('page');
        $limit = request()->param('limit');
        $type = request()->param('type');
        $start = ($page-1) * $limit;
        $modules = input("modules");
        $value =input("value");


        if($value && $modules){
            $info = Db('user')
            ->alias("user")
            ->join('filesalary_info', 'user.id = filesalary_info.user_id')
            ->where($modules,'LIKE','%'.$value .'%')
            ->where('filesalary_info.isdelete',0)
            ->limit($start,$limit)
            ->select();
            
            $count =  Db('user')
            ->limit($start,$limit)
            ->count();
        }else{
            $info = Db('user')
            ->alias("user")
            ->join('filesalary_info', 'user.id = filesalary_info.user_id')
            ->where('filesalary_info.isdelete',0)
            ->limit($start,$limit)
            ->select();
            
            $count =  Db('user')
            ->limit($start,$limit)
            ->count();
        }

        

        $msg = [
            'code' => 0,
            'msg' => '查询成功',
            'data' => $info,
            'count' => $count
        ];
        
        echo json_encode($msg);
    }
    //用户页面编辑信息处理
    public function editPost(){
        $id = request()->param('id');
        $status=Db('user')
        ->alias("user")
        ->join('filesalary_info', 'user.id = filesalary_info.user_id')
        ->where('user.id','=',$id)
        ->update([
            "filesalary_info.job_type" =>request()->param("job_type"),
            "filesalary_info.job_level" =>request()->param("job_level"),
            "filesalary_info.job_change_time" =>request()->param("job_change_time"),
            "filesalary_info.salary_level" =>request()->param("salary_level"),
            "filesalary_info.salary_change_time" =>request()->param("salary_change_time"),
            "filesalary_info.job_type_on_campus" =>request()->param("job_type_on_campus"),
            "filesalary_info.job_level_on_campus" =>request()->param("job_level_on_campus"),
            "filesalary_info.job_level_on_campus_time" =>request()->param("job_level_on_campus_time")
        ]);
        
        if($status){
            $this->success('更新成功');
        }else{
            $this->error('更新失败');
        }
    }
}